//
//  MainViewController.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/11.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

   @objc private func plusBtnDidClick(){
        
        print(__FUNCTION__)
    let compose = ComposeViewController()
    let nav = UINavigationController(rootViewController: compose)
    presentViewController(nav, animated: true, completion: nil)
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
       addChildViewControllers()
        
        let mainTabBar = MainTabBar()
        
        
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: UIControlEvents.TouchUpInside)

    
    }
    
   private func addChildViewControllers(){
        
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
                addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
                addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
                addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
        
        
    
    }

   private func addChildViewController(vc : UIViewController , imageName : String, title : String){
        
       // let home = HomeTableViewController()
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        

    self.tabBar.tintColor = UIColor.orangeColor()
        
               
        vc.title = title
        
        
        let nav = BaseNavViewController(rootViewController: vc)
        
        addChildViewController(nav)
        
        
        
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
